﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBL;
using System.Data.SqlClient;
namespace MyWeb.Module
{
    public partial class mod_MenuMain : System.Web.UI.UserControl
    {
        MenuDBL menubl = new MenuDBL();
        protected void Page_Load(object sender, EventArgs e)
        {
            GetMainMenu();
        }

        /*
        public void Menus()
        {
            string Chuoi = "";
            var menu = (from m in db.menus where m.menu_types == "ON" select m).ToList();
            for (int i = 0; i < menu.Count; i++)
            {

                Chuoi += "<ul>";
                Chuoi += "<li>";
                Chuoi += "<a href=" + @Url.Action(menu[i].link) + ">" + menu[i].name + "</a>";
                var submenu = (from s in db.Vsubmenus where s.submenu_types == "ON" orderby s.suborders ascending select s).ToList();

                Chuoi += "<ul>";
                for (int j = 0; j < submenu.Count; j++)
                {
                    if (submenu[j].idmenu == menu[i].id)
                    {
                        Chuoi += "<li>";
                        if ((submenu[j].id == 4) || (submenu[j].id == 5))
                            Chuoi += "<a target='_blank' href=" + submenu[j].sublink + ">" + submenu[j].subname + "</a>";
                        else
                            Chuoi += "<a href=" + @Url.Action(submenu[j].sublink) + ">" + submenu[j].subname + "</a>";
                        Chuoi += "</li>";
                    }
                }
                Chuoi += "</ul>";
                Chuoi += "</li>";
                Chuoi += "</ul>";
            } ViewBag.View = Chuoi;

        }
        */
        private void GetMainMenu()
        {  
            DataTable dt = new DataTable();
            dt = menubl.MainMenu();   
            DataRow[] drowpar = dt.Select("ParenID=" + 0);

            foreach (DataRow dr in drowpar)
                MenuMain.Items.Add(new MenuItem(dr["name"].ToString(),dr["Id"].ToString(), "",dr["Order"].ToString()));
            foreach (DataRow dr in dt.Select("ParenId >" + 0))
            {
                MenuItem mnu = new MenuItem(dr["name"].ToString(), dr["Id"].ToString(), "", dr["Order"].ToString());
                MenuMain.FindItem(dr["ParenId"].ToString()).ChildItems.Add(mnu);

            }


        }
    }
}